<?php 
class LoginAction extends Action{
/*	function _initialize(){
		if(isset($_SESSION['main_name'])){
			$this->redirect('Index/index');
		}
	}*/
	
	public function index(){
		$this->display();
	}
	
	public function login(){
		$map=array();
//		$map['login_ip']=$_SERVER['REMOTE_ADDR'];
//		$map['login']=time();
		$name=trim($_POST['name']);
		$pwd=md5(trim($_POST['password'])."&abc");

		$member_model=M('admin_user');
		$member_model->getByUsername($name);
		$name2=$member_model->username;
		$pwd2=$member_model->password;

		$id=$member_model->id;
		
		$verifyCode = trim($_POST['verifyTest']);
		if(md5($verifyCode) != $_SESSION['verify']){
			
           $this->error(L('验证码错误').' [ <a href="javascript:history.back()">return</a> ]');
        }
		
		if($name===$name2&&$pwd===$pwd2){
			$_SESSION['main_name']=$name2;
			$member_model->where('id='.$id)->save($map);
            //$this->redirect('Member/index', array(),1,'<script language="JavaScript">alert("Login success")</script>');
            $this->redirect('Index/index');
		}else {
			$this->error('用户名或密码错误!');
		}
	}
	
	public function out(){
		
		if(isset($_SESSION['main_name'])){
			unset($_SESSION['main_name']);
			$this->redirect('Index/index');
		}
	}
	
	
	public function verify()
    {
        $type	 =	 isset($_GET['type'])?$_GET['type']:'gif';
        import("@.ORG.Image");
        Image::buildImageVerify(4,1,$type);
    }
}
?>